<?php
$dirnameshort = substr(dirname(__FILE__),0,25);

include_once($dirnameshort.'../dbutil.php');
$renew = new DBUtil();
	  		$querySql='SELECT a.dealline,a.dnumber as goodid,b.id,c.listnumber as distribution,c.create_time,d.*,d.unitprice*d.coefficient*a.goodvolume as daypay FROM t_good_ingoods a
	  		LEFT JOIN tms_settlement_vender b ON a.agentid=b.peopleid
	  		LEFT JOIN t_goods_outlist c ON a.agentid=c.agentid
	  		LEFT JOIN cms_good_storage d ON a.goodtype=d.typeName
	  		 WHERE a.cukutype!="2" 
	  GROUP BY a.dealline,a.dnumber
	  		 	UNION 
	  		 	SELECT a.dealline,a.goodidc as goodid,b.id,c.listnumber as distribution,c.create_time,d.*,d.unitprice*d.coefficient*a.packgevolum as daypay FROM t_good_inpackage a
	  		 	LEFT JOIN t_good_ingoods f ON a.goodidc=f.dnumber AND a.dealline=f.dealline
	  		 	LEFT JOIN tms_settlement_vender b ON f.agentid=b.peopleid
	  		LEFT JOIN t_goods_outlist c ON f.agentid=c.agentid
	  		LEFT JOIN cms_good_storage d ON a.ptype=d.typeName
	  		 	WHERE a.cukutype!="2"
GROUP BY a.dealline,a.goodidc
	  		 ';

$adp = $renew->getAll($querySql);
try{
	$timenow=time();
	foreach ($adp as $key => $value) {
		$sqlArr='INSERT INTO tms_settlement_money (amounts,operatime,addOrred,tvenderid,outhousetime,warehousenum,outwarehousenum) VALUES ("'.$value['daypay'].'","'.$timenow.'","2","'.$value['id'].'","'.$value['create_time'].'","'.$value['dealline'].'","'.$value['distribution'].'")';
		$renew->query($sqlArr);
	}
	$renew->commit();
	echo "数据新增成功!";
}
catch (Exception $e){
    $renew->rollback();
    echo "数据新增失败!";
}

	  	

